import {RootRequest} from "@/apis/_request/RootRequest";
import {RequestUtils} from "@/utils/RequestUtils";
import {WalletType} from "@/typing/wallet";
import {EnumDragon} from "@/components/NFTOperate";
import {Paging} from "@/typing/paging/paging";


export interface User {
    address: string;
    inviteUrl: string;
    avatar: string;
    balance: number;
    gpBalance: number;
    pubkey: string;
    userName: string;
}

export enum NFTEnum {
    "Box" = 1,
    "dragon" = 2,
}

export interface NFT {
    buttons: {
        inscribing: boolean;
        list: boolean;
        open: boolean;
        opening: boolean;
        transfer: boolean;
        transferring: boolean;
        unlist: boolean;
    };
    description: string;
    hashPower: number;
    image: string;
    inscriptionId: string;
    inscriptionUrl: string;
    level: number;
    name: string;
    rarity: number;
    rarityType: EnumDragon;
    status: number;
    tokenId: string;
    type: NFTEnum;
}

export interface Coin {
    balance: number;
    icon: string;
    name: string;
    symbol: string;
}

export interface Tip {
    title: string;
    message: string;
}

export interface TaskStatus {
    telegramUserName: number;
    xUserName: number;
    assetsStatus: number;
    bindXStatus: number;
    followXStatus: number;
    joinTelegramStatus: number;
    telegramInviteUrl: string;
}

class UserApi extends RootRequest {
    constructor() {
        super();
    }

    preload(address: string) {
        return RequestUtils.get<string>({url: "/api/user/preload", data: {address}});
    }

    login(data: { address: string, pubkey: string, sign: string, walletType: WalletType, inviteCode: string | null }) {
        return RequestUtils.post<{ address: string, token: string, tokenExpire: number }>({
            url: "/api/user/login",
            data
        });
    }

    info() {
        return RequestUtils.get<User>({url: "/api/user/info"});
    }

    update(data: { userName?: string, avatar?: string }) {
        return RequestUtils.post<string>({url: "/api/user/update", data});
    }

    avatars() {
        return RequestUtils.get<string[]>({url: "/api/user/avatars"});
    }

    nfts(data: any) {
        return RequestUtils.get<Paging<NFT>>({url: "/api/user/nfts", data});
    }

    coins(data: any) {
        return RequestUtils.get<Paging<Coin>>({url: "/api/user/coins", data});
    }

    tips() {
        return RequestUtils.get<Paging<Tip>>({url: "/api/user/tips"});
    }

    taskStatus() {
        return RequestUtils.get<TaskStatus>({url: "/api/user/taskStatus"});
    }

    xAuthed(code: string) {
        return RequestUtils.post<Paging<Tip>>({url: "/api/user/xAuthed", data: {code}});
    }
}

export const userApi = new UserApi();
